package com.copm.ifm.servers.sys.controller;

import com.copm.ifm.base.api.pojo.PageDTO;
import com.copm.ifm.base.api.pojo.PageVO;
import com.copm.ifm.base.basic.ServiceResponse;
import com.copm.ifm.base.service.base.BaseController;
import com.copm.ifm.servers.sys.dto.SysEcTypeDTO;
import com.copm.ifm.servers.sys.entity.SysEcType;
import com.copm.ifm.servers.sys.service.SysEcTypeService;
import com.copm.ifm.servers.sys.vo.SysEcTypeVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 能耗表相关接口类
 *
 * @author tp
 * @date 2021/1/5 10:39
 */
@Slf4j
@Api(tags = "能耗类型/sys-ec")
@RestController
@RequestMapping("/sys-ec")
public class SysEcTypeController extends BaseController {

    @Autowired
    SysEcTypeService sysEcTypeService;

    @ApiOperation("分页")
    @PostMapping("/page")
    public ServiceResponse<PageVO<SysEcTypeVO>> page(@RequestBody PageDTO<SysEcTypeDTO> param) {
        PageVO<SysEcTypeVO> result = sysEcTypeService.selectForPage(param);
        return success(result);
    }

    @ApiOperation("查询-根据id")
    @GetMapping("/by/id")
    public ServiceResponse<SysEcTypeVO> getById(@ApiParam(value = "主键id", required = true)
                                                @RequestParam int id) {
        return success(sysEcTypeService.selectVOById(id));
    }

    @ApiOperation("保存")
    @PostMapping
    public ServiceResponse<SysEcType> save(@RequestBody SysEcType entity) {
        sysEcTypeService.save(entity);
        return success(entity);
    }

    @ApiOperation("修改-根据id")
    @PutMapping
    public ServiceResponse<SysEcType> update(@RequestBody SysEcType entity) {
        sysEcTypeService.updateEntityById(entity);
        return success(entity);
    }

    @ApiOperation("删除-根据id")
    @DeleteMapping("/by/id")
    public ServiceResponse<?> deleteById(@ApiParam(value = "主键id", required = true) @RequestParam int id) {
        sysEcTypeService.updateDeleted(id);
        return success();
    }
}
